package leetcode.秋招.广;

import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/9/17 21:50
 * @description：
 */
public class Main6 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        if (num == 0 || num == 1) {
            System.out.println(0);
            return;
        }
        if (num == 2 || num == 3) {
            System.out.println(num - 1);
            return;
        }
        int result = 1;
        while (num > 4) {
            result *= 3;
            num -= 3;
        }
        System.out.println(result * num);
    }
}
